package com.tinem.platform.web.gateway.controller;

import com.tinem.platform.web.gateway.filter.AuthorizeGatewayFilterFactory;
import com.tinem.platform.web.gateway.filter.CountryBlacklistGatewayFilterFactory;
import com.tinem.platform.web.gateway.filter.LoginGatewayFilterFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author fengzhihao
 * @version v1
 * @program: platform
 * @className SwaggerController
 * @description curl 127.0.0.1:8080/cache/refresh.api
 * @site
 * @company
 * @create 2021/12/3 12:00:12
 */
@RestController
@RequestMapping("/cache/")
public class CacheController {

    @Value("${info.instance.name}")
    String instanceNname;
    @Resource
    LoginGatewayFilterFactory loginGatewayFilterFactory;

    @Resource
    AuthorizeGatewayFilterFactory authorizeGatewayFilterFactory;

    @Resource
    CountryBlacklistGatewayFilterFactory countryBlacklistGatewayFilterFactory;

    @GetMapping("loginRefresh.api")
    public Object loginRefresh(){
        loginGatewayFilterFactory.refresh();
        loginGatewayFilterFactory.clearCache();
        return instanceNname;
    }

    @GetMapping("authorizeRefresh.api")
    public Object authorizeRefresh(){
        authorizeGatewayFilterFactory.refresh();
        authorizeGatewayFilterFactory.clearCache();
        return instanceNname;
    }

    @GetMapping("refresh.api")
    public Object refresh(){
        loginGatewayFilterFactory.refresh();
        loginGatewayFilterFactory.clearCache();
        authorizeGatewayFilterFactory.refresh();
        authorizeGatewayFilterFactory.clearCache();
        countryBlacklistGatewayFilterFactory.refresh();
        return instanceNname;
    }

}
